﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Assignment_5_Amanda_Boström
{
    class InputUtility
    {
        /// <summary>
        /// Converts a string represented integer value into a integer type, and validates
        /// the converted value >= 0.0
        /// </summary>
        /// <param name="stringToConvert"></param>
        /// <param name="intOutValue"></param>
        /// <returns></returns>
        public static bool GetInteger(string stringToConvert, out int intOutValue)
        {
            //Try Parse a string encoded integer into an integer data type
            bool goodNumber = int.TryParse(stringToConvert, out intOutValue);
            if (goodNumber)
                goodNumber = intOutValue >= 0.0;

            return goodNumber;
            
        }
        /// <summary>
        /// Converts a string represented double value into a double type, and validates
        /// the converted value >= 0.0
        /// </summary>
        /// <param name="stringToConvert"></param>
        /// <param name="dblOutValue"></param>
        /// <returns></returns>
        public static bool GetDouble(string stringToConvert, out double dblOutValue)
        {
            // Try Parse a string encoded double into a double data type
            bool goodNumber = double.TryParse(stringToConvert, out dblOutValue);
            if (goodNumber)
                goodNumber = dblOutValue >= 0.0;

            return goodNumber;
        }
        /// <summary>
        /// Validates a string and returns true if the string is not null after trimming.
        /// Does not need an out-parameter because the parameter contains data - the string
        /// to be validated
        /// </summary>
        /// <param name="stringToCheck"></param>
        /// <returns></returns>
        public static bool ValidateString(string stringToCheck)
        {
            //delete the beginning and ending spaces
            string strIn = stringToCheck.Trim();

            //returns True if the string is not empty after a trim and not null
            return !string.IsNullOrEmpty(strIn);
        }
    }
}
